package com.hex.ds.hdrs.engine.controller;

import com.hex.bigdata.hbda.annotation.Log;
import com.hex.bigdata.hbda.base.Page;
import com.hex.ds.hdrs.app.vo.AppAgentVo;
import com.hex.ds.hdrs.common.page.PageData;
import com.hex.ds.hdrs.engine.service.RamService;
import com.hex.ds.hdrs.engine.vo.DispatcherExecVo;
import com.hex.ds.hdrs.engine.vo.ProcessorExecVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;

/**
 * @author lwz
 * @date 2020-12-28
 * @des
 */
@Slf4j
@RestController
@RequestMapping("/api/ram")
@Api(tags = "内存操作")
public class RamController {

    @Autowired
    private RamService ramService;

    @Log("获取当前应用今日任务执行情况")
    @ApiOperation("获取当前应用今日任务执行情况")
    @GetMapping(value = "/findTaskRunInfCurrentApp")
    public ResponseEntity<Object> findTaskRunInfCurrentApp(@RequestParam @NotBlank String appCode) {
        log.info("进入了【RamController的findTaskRunInfCurrentApp方法】");
        Map map = this.ramService.findTaskRunInfCurrentAppInfo(appCode);
        return new ResponseEntity(map, HttpStatus.OK);
    }

    /**
     * @Method: findHisTaskRunInfCurrentApp
     * @Param: []
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object>
     * @Description: 获取当前应用历史任务执行情况
     * @Author: ji.tang
     * @Date: 2022/6/14 18:51
     * @Version: V1.0
     */
    @Log("获取当前应用历史任务执行情况")
    @ApiOperation("获取当前应用历史任务执行情况")
    @GetMapping(value = "/findHisTaskRunInfCurrentApp")
    public ResponseEntity<Object> findHisTaskRunInfCurrentApp(@RequestParam @NotBlank String appCode) {
        log.info("进入了【RamController的findHisTaskRunInfCurrentApp方法】");
        Map map = this.ramService.findHisTaskRunInfCurrentApp(appCode);
        return new ResponseEntity(map, HttpStatus.OK);
    }


    @Log("获取所有应用任务执行情况")
    @ApiOperation("获取所有应用任务执行情况")
    @GetMapping(value = "/findAllJobInfByCurrentUser")
    public ResponseEntity<Object> findAllJobInfByCurrentUser() {
        log.info("进入了【RamController的findAllTaskRunInf方法】");
        Map map = this.ramService.findAllJobInfByCurrentUser();
        return new ResponseEntity(map, HttpStatus.OK);
    }


    @Log("获取当前应用所属节点列表")
    @ApiOperation("获取当前应用所属节点列表")
    @GetMapping(value = "/getCycleJobRunInfCurrentApp")
    public ResponseEntity<Object> getCycleJobRunInf(@RequestParam @NotBlank String appCode) {
        log.info("进入了【AgentConfController的getCycleJobRunInfCurrentApp方法】");
        List<AppAgentVo> list = this.ramService.getCycleJobRunInfCurrentApp(appCode);
        return new ResponseEntity(list, HttpStatus.OK);
    }

    @Log("查询内存处理器线程")
    @ApiOperation("查询内存处理器线程")
    @GetMapping(value = "/qryProThread")
    public ResponseEntity<Object> qryProThread(ProcessorExecVo processorExecVO, Page page) {
        PageData pageData = new PageData(this.ramService.qryProThread(processorExecVO, page), page);
        return new ResponseEntity(pageData, HttpStatus.OK);
    }

    @Log("查询内存分发器线程")
    @ApiOperation("查询内存分发器线程")
    @GetMapping(value = "/qryDisThread")
    public ResponseEntity<Object> qryDisThread(DispatcherExecVo dispatcherExecVO, Page page) {
        PageData pageData = new PageData(this.ramService.qryDisThread(dispatcherExecVO, page), page);
        return new ResponseEntity(pageData, HttpStatus.OK);
    }

    @Log("获取某个作业内存中信息")
    @ApiOperation("获取某个作业内存中信息")
    @PostMapping("getJobTaskInf")
    public ResponseEntity<Object> getJobTaskInf(@RequestBody Map paramMap) {
        log.debug("获取某个作业内存中信息【RamController.getJobTaskInf】");
        Map resultMap = this.ramService.getJobTaskInf(paramMap);
        return new ResponseEntity<>(resultMap, HttpStatus.OK);
    }

    @Log("获取管理员首页头部信息")
    @ApiOperation("获取管理员首页头部信息")
    @GetMapping(value = "findAdminTopData")
    public ResponseEntity<Object> findAdminTopData() {
        log.debug("获取管理员首页头部信息【RamController.findAdminTopData】");
        return new ResponseEntity<>(this.ramService.findAdminTopData(), HttpStatus.OK);
    }

    @Log("查询首页周期任务当日/历史各状态数量")
    @ApiOperation("查询首页周期任务当日/历史各状态数量")
    @GetMapping(value = "/findPeriodTaskCountTopDataNotApp")
    public ResponseEntity<Object> findPeriodTaskCountTopDataNotApp() {
        log.info("进入了【RamController的findPeriodTaskCountTopDataNotApp方法】");
        Map map = this.ramService.findPeriodTaskCountTopDataNotApp();
        return new ResponseEntity(map, HttpStatus.OK);
    }

    @Log("查询首页定时任务当日/历史各状态数量")
    @ApiOperation("查询首页定时任务当日/历史各状态数量")
    @GetMapping(value = "/findCronTaskCountTopDataNotApp")
    public ResponseEntity<Object> findCronTaskCountTopDataNotApp() {
        log.info("进入了【RamController的findCronTaskCountTopDataNotApp方法】");
        Map map = this.ramService.findCronTaskCountTopDataNotApp();
        return new ResponseEntity(map, HttpStatus.OK);
    }

    @Log("查询应用下周期任务当日/历史各状态数量")
    @ApiOperation("查询应用下周期任务当日/历史各状态数量")
    @GetMapping(value = "/findPeriodTaskCountTopData")
    public ResponseEntity<Object> findPeriodTaskCountTopData(@RequestParam @NotBlank String appCode) {
        log.info("进入了【RamController的findPeriodTaskCountTopData方法】");
        Map map = this.ramService.findPeriodTaskCountTopData(appCode);
        return new ResponseEntity(map, HttpStatus.OK);
    }

    @Log("查询应用下定时任务当日/历史各状态数量")
    @ApiOperation("查询应用下定时任务当日/历史各状态数量")
    @GetMapping(value = "/findCronTaskCountTopData")
    public ResponseEntity<Object> findCronTaskCountTopData(@RequestParam @NotBlank String appCode) {
        log.info("进入了【RamController的findCronTaskCountTopData方法】");
        Map map = this.ramService.findCronTaskCountTopData(appCode);
        return new ResponseEntity(map, HttpStatus.OK);
    }
}
